package edu.neu.cs6515.test.runner;

import java.util.List;

import com.google.common.collect.ImmutableList;

import edu.neu.cs6515.board.rules.Rule;
import edu.neu.cs6515.xml.Bad;
import edu.neu.cs6515.xml.Board;
import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Score;

/**
 * Testrunner for integration-tests of the Board
 */
public class BoardTestRunner extends AbstractTestRunner {

    /**
     * C'tor, initializes board, no moves, placements etc
     * @param boardFromXML xml info to initialize board
     */
    public BoardTestRunner(final Board boardFromXML) {
        super(boardFromXML);
    }

    @Override
    protected void initializePlacements(final List<Placement> placements) {
        for (final Placement placement : placements) {
            List<Rule> brokenRules = board.getBrokenRules(placement);
            if (brokenRules.size() > 0) {
                gameResults.setBad(ImmutableList.of(new Bad(brokenRules.get(0)
                        .getReason())));
                return;
            } else {
                final Score scoreOfMove = board.scoreAMove(placement);
                gameResults.getScore().add(scoreOfMove);
                board.updateHexagonBoard(placement);
            }
        }
    }
}
